home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 November / CHIP Kasım 1997.iso / DEMOLAR / FPAGE98 / DATA.1 / DB_StartBotASP.txt < prev    next >
Text File  |  1997-07-30  |  3KB  |  77 lines

  1. <%
  2. ' Substitute in form parameters into the query string
  3. fp_sQry = "[*]InsertSqlQuery[*]"
  4. fp_sDefault = "[*]InsertDefaultFields[*]"
  5. fp_iCurrent = 1
  6. fp_fError = False
  7. fp_bBlankField = False
  8. Do While (Not fp_fError) And (InStr(fp_iCurrent, fp_sQry, "%%") <> 0)
  9.     ' found a opening quote, find the close quote
  10.     fp_iStart = InStr(fp_iCurrent, fp_sQry, "%%")
  11.     fp_iEnd = InStr(fp_iStart + 2, fp_sQry, "%%")
  12.     If fp_iEnd = 0 Then
  13.         fp_fError = True
  14.         Response.Write "<B>Database Region Error: mismatched parameter delimiters</B>"
  15.     Else
  16.         fp_sField = Mid(fp_sQry, fp_iStart + 2, fp_iEnd - fp_iStart - 2)
  17.         fp_sValue = Request.Form(fp_sField)
  18.  
  19.         ' if the named form field doesn't exist, make a note of it
  20.         If (len(fp_sValue) = 0) Then
  21.             fp_iCurrentField = 1
  22.             fp_bFoundField = False
  23.             Do While (InStr(fp_iCurrentField, fp_sDefault, fp_sField) <> 0) _
  24.                 And Not fp_bFoundField
  25.                 fp_iCurrentField = InStr(fp_iCurrentField, fp_sDefault, fp_sField)
  26.                 fp_iStartField = InStr(fp_iCurrentField, fp_sDefault, "=")
  27.                 If fp_iStartField = fp_iCurrentField + len(fp_sField) Then
  28.                     fp_iEndField = InStr(fp_iCurrentField, fp_sDefault, "&")
  29.                     If (fp_iEndField = 0) Then fp_iEndField = len(fp_sDefault) + 1
  30.                     fp_sValue = Mid(fp_sDefault, fp_iStartField+1, fp_iEndField-1)
  31.                     fp_bFoundField = True
  32.                 Else
  33.                     fp_iCurrentField = fp_iCurrentField + len(fp_sField) - 1
  34.                 End If
  35.             Loop
  36.         End If
  37.  
  38.         ' this next finds the named form field value, and substitutes in
  39.         ' doubled single-quotes for all single quotes in the literal value
  40.         ' so that SQL doesn't get confused by seeing unpaired single-quotes
  41.         fp_sValue = Replace(Replace(fp_sValue, "'", "''"), """", """""")
  42.  
  43.         If (Mid(fp_sQry, fp_iStart - 1, 1) <> """") And _
  44.             (Mid(fp_sQry, fp_iStart - 1, 1) <> "'") And _
  45.             Not IsNumeric(fp_sValue) Then
  46.             fp_sValue = ""
  47.         End If
  48.  
  49.         If (len(fp_sValue) = 0) Then fp_bBlankField = True
  50.  
  51.         fp_sQry = Left(fp_sQry, fp_iStart - 1) + fp_sValue + _
  52.             Right(fp_sQry, Len(fp_sQry) - fp_iEnd - 1)
  53.         
  54.         ' Fixup the new current position to be after the substituted value
  55.         fp_iCurrent = fp_iStart + Len(fp_sValue)
  56.     End If
  57. Loop
  58.  
  59. If Not fp_fError Then
  60.     ' Use the connection string directly as entered from the wizard
  61.     On Error Resume Next
  62.     set fp_rs = CreateObject("ADODB.Recordset")
  63.     fp_rs.Open fp_sQry, "[*]InsertConnString[*]"
  64.     If Err.Description <> "" Then
  65.         Response.Write "<B>Database Error: " + Err.Description + "</B>"
  66.         if fp_bBlankField Then
  67.             Response.Write "  One or more form fields were empty."
  68.         End If
  69.     Else
  70.         ' Check for the no-record case
  71.         If fp_rs.EOF And fp_rs.BOF Then
  72.             Response.Write "<B>No Records Returned</B>"
  73.         Else
  74.             ' Start a while loop to fetch each record in the result set
  75.             Do Until fp_rs.EOF
  76. %>
  77.